/*
 * Copyright (c) 2020 - present, Inspur Genersoft Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.inspur.edp.sgf.core.config;

import com.inspur.edp.sgf.api.service.EapiConfigService;
import com.inspur.edp.sgf.api.service.InvokeService;
import com.inspur.edp.sgf.core.cache.EapiConfigCacheManager;
import com.inspur.edp.sgf.core.interceptor.EapiConfigCxfInterceptor;
import com.inspur.edp.sgf.core.manager.EapiConfigManager;
import com.inspur.edp.sgf.core.service.EapiConfigServiceImpl;
import com.inspur.edp.sgf.core.service.InvokeServiceImpl;
import io.iec.edp.caf.commons.layeringcache.manager.CacheManager;
import io.iec.edp.caf.permission.api.manager.runtime.PermissionManager;
import io.iec.edp.caf.rpc.api.service.RpcClient;
import org.apache.cxf.Bus;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;

/**
 * 功能描述: @ClassName: BeanConfig @Author: Fynn Qi @Date: 2019/7/22 19:00 @Version: V1.0
 */
@Configuration(value = "com.inspur.edp.sgf.core.config.EApiBeanConfig", proxyBeanMethods = false)
public class EApiBeanConfig {

    @Order()
    @Bean("com.inspur.edp.sgf.core.config.EApiBeanConfig.EapiConfigCxfInterceptor")
    public EapiConfigCxfInterceptor eapiAuthInterceptor(EapiConfigManager configManager, PermissionManager permissionManager) {
        return new EapiConfigCxfInterceptor(configManager, permissionManager);
    }

    @Order()
    @Bean("com.inspur.edp.sgf.core.config.EApiBeanConfig.initEapiConfigBus")
    public Boolean initEapiConfigBus(Bus bus, EapiConfigCxfInterceptor cxfInInterceptor) {
        bus.getInInterceptors().add(cxfInInterceptor);
        return true;
    }

    @Bean("com.inspur.edp.sgf.core.manager.EapiConfigManager")
    public EapiConfigManager eapiConfigManager(RpcClient rpcClient, EapiConfigCacheManager eapiConfigCacheManager) {
        return new EapiConfigManager(rpcClient, eapiConfigCacheManager);
    }

    @Bean("com.inspur.edp.sgf.core.service.EapiConfigServiceImpl")
    public EapiConfigService configService(EapiConfigManager eapiConfigManager) {
        return new EapiConfigServiceImpl(eapiConfigManager);
    }

    @Bean("com.inspur.edp.sgf.core.config.EApiBeanConfig.EapiConfigCacheManager")
    public EapiConfigCacheManager eapiConfigCacheManager(CacheManager cacheManager) {
        return new EapiConfigCacheManager(cacheManager);
    }

    @Bean("com.inspur.edp.sgf.core.config.EApiBeanConfig.InvokeService")
    public InvokeService invokeService() {
        return new InvokeServiceImpl();
    }

}
